﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Web.Personals.IPresenters;
using Core.DataAccess;
using SonCa.SocialNetwork.Web.Personals.Presenters;
using Core.Common;
using SonCa.SocialNetwork.Web.Personals.ASCX;
using System.ComponentModel.Composition;
using Core.Interfaces;

namespace SonCa.SocialNetwork.Web.Personals
{
    public partial class PersonalFriends : System.Web.UI.Page, IPersonalFriendPresenter
    {
        private PersonalFriendPresenter _presenter;

        [Import]
        private IUserSession _userSession;                

        protected void Page_Load(object sender, EventArgs e)
        {
            MEFManager.Compose(this);
            _presenter = new PersonalFriendPresenter();
            _presenter.Init(this);

            hdfAccountID_Personalfriend.Value = _userSession.CurrentUser.AccountID.ToString();
        }

        protected void rpt_PersonalFriends_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ListFriends ucListFriends = e.Item.FindControl("ListFriends1") as ListFriends;
                Account account = (Account)e.Item.DataItem;
                string level = _presenter.GetLevelByLevelID(Convert.ToInt32(account.LevelID));
                ucListFriends.DisplayFriends(account,level);
            }
        }

        public void DisplayListFriend(List<Account> lstAccountFriends)
        {
            if (lstAccountFriends.Count > 0)
            {                
                rpt_PersonalFriends.DataSource = lstAccountFriends;                
                rpt_PersonalFriends.DataBind();
            }
            else
            {
                lblMessage_PersonalFriend.Text = "Bạn chưa có bạn bè, hãy mau kết bạn";
                lblMessage_PersonalFriend.Visible = true;
            }
        }
    }
}